﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

/// <summary>
/// Summary description for ClassLookUp
/// </summary>
public class ClassLookUp
{
    private static Dictionary<string, string> classDic;
    private static readonly object padlock = new object();
    private static XmlNodeReader reader;
    private static const string FILEPATH = "class.xml";
    private static const string CLASS = "class";
    private static const string KEY = "key";
    private static const string VALUE = "value";

    private static void Initialize()
    { 
        lock (padlock)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(FILEPATH);
            classDic = new Dictionary<string, string>();
            XmlNodeList nodes = doc.GetElementsByTagName(CLASS);
            foreach(XmlNode child in nodes)
            {
                classDic.Add(child[KEY].InnerText,child[VALUE].InnerText);
            }
        }
    }

    private static Dictionary<string,string> getInstance()
    {
        lock(padlock)
        {
            if(classDic == null)
            {
                Initialize();
            }
            return classDic;
        }
    }

    public static string lookup(string request)
    {
        lock (padlock)
        {
            return getInstance()[request];
        }
    }
}